<?php
	require_once '../Tool/Common/PrepareInput.php';

    $NRIC=$CustomerName=$Date=$DateTo=$CentreLocation=$ActivityId="";

    if(isset($_REQUEST['NRIC'])) { 
        $NRIC=prepareInput($_REQUEST['NRIC']); 
    }
    if(isset($_REQUEST['CustomerName'])) { 
        $CustomerName=prepareInput($_REQUEST['CustomerName']); 
    }
    if(isset($_REQUEST['SearchDate'])) { 
        $Date=prepareInput($_REQUEST['SearchDate']); 
    }
    if(isset($_REQUEST['SearchDateTo'])) { 
        $DateTo=prepareInput($_REQUEST['SearchDateTo']); 
    }
    if(isset($_REQUEST['CentreLocation'])) { 
        $CentreLocation=prepareInput($_REQUEST['CentreLocation']); 
    }
    if(isset($_REQUEST['ActivityId'])) { 
        $ActivityId=prepareInput($_REQUEST['ActivityId']); 
    }

    $result=array();

    $result['flagNRIC']=0;
    $result['flagCustomerName']=0;
    $result['flagDate']=0;
    $result['flagDateTo']=0;
    $result['flagDateCompare']=1;
    $result['flagCentreLocation']=0;
    $result['flagActivityId']=0;

    if(!empty($NRIC)&&preg_match("/^[0-9A-Za-z]*$/",$NRIC)){
		$result['flagNRIC']=1;
	}
    if(empty($NRIC)){
        $result['flagNRIC']=1;
    }
    if(!empty($CustomerName)&&preg_match("/^[0-9A-Za-z''-:. ]*$/",$CustomerName)){
        $result['flagCustomerName']=1;
    }
    if(empty($CustomerName)){
        $result['flagCustomerName']=1;
    }
    if(!empty($Date)&&preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/",$Date)){
        $result['flagDate']=1;
    }
    if(empty($Date)){
        $result['flagDate']=1;
    }
    if(!empty($DateTo)&&preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/",$DateTo)){
        $result['flagDateTo']=1;
    }
    if(empty($Date)){
        $result['flagDateTo']=1;
    }
    if(!empty($Date)&&!empty($DateTo)){
        if($Date>$DateTo){
            $result['flagDateCompare']=0;
        }
    }
    if(!empty($CentreLocation)&&preg_match("/^[0-9]*$/",$CentreLocation)){
        $result['flagCentreLocation']=1;
    }
    if(empty($CentreLocation)){
        $result['flagCentreLocation']=1;
    }
    if(!empty($ActivityId)&&preg_match("/^[0-9]*$/",$ActivityId)){
        $result['flagActivityId']=1;
    }
    if(empty($ActivityId)){
        $result['flagActivityId']=1;
    }

    echo json_encode($result);
?>